﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace GW2LastOnline.Controls
{
    class Combo : ComboBox
    {
        public Combo()
            : base()
        {
            base.DoubleBuffered = true;
            base.DrawMode = DrawMode.OwnerDrawFixed;
            base.DrawItem += new DrawItemEventHandler(Combo_DrawItem);
            this.SelectionBackColor = SystemColors.Highlight;
            this.SelectionForeColor = SystemColors.HighlightText;
            this.ListBackColor = SystemColors.Window;
        }

        public Color ListBackColor
        {
            get;
            set;
        }

        public Color SelectionBackColor
        {
            get;
            set;
        }

        public Color SelectionForeColor
        {
            get;
            set;
        }

        void Combo_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
                return;

            //ComboBox combo = sender as ComboBox;

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                if ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit)
                {
                    e.Graphics.FillRectangle(new SolidBrush(base.BackColor), e.Bounds);
                    e.Graphics.DrawString(base.Items[e.Index].ToString(), e.Font, new SolidBrush(base.ForeColor), new Point(e.Bounds.X, e.Bounds.Y));
                }
                else
                {
                    e.Graphics.FillRectangle(new SolidBrush(this.SelectionBackColor), e.Bounds);
                    e.Graphics.DrawString(base.Items[e.Index].ToString(), e.Font, new SolidBrush(this.SelectionForeColor), new Point(e.Bounds.X, e.Bounds.Y));
                }
            }
            else
            {
                e.Graphics.FillRectangle(new SolidBrush(this.ListBackColor), e.Bounds);
                e.Graphics.DrawString(base.Items[e.Index].ToString(), e.Font, new SolidBrush(base.ForeColor), new Point(e.Bounds.X, e.Bounds.Y));
            }

            e.DrawFocusRectangle();
        }
    }
}
